/***************************************************
  > Copyright (C) 2024 ==KINGYI== All rights reserved.
  > File Name: pm8.8.two.c
  > Author:
  > Mail:
  > Created Time: Thu 08 Aug 2024 04:24:13 AM PDT
 ***************************************************/
// 实现一个队列，queue.c queue.h

#include "queue.h"

STU *create_queue()  //创建头节点
{
	STU *head = (STU *)malloc(sizeof(STU));
	memset(head, 0, sizeof(STU));
	head->next = NULL;
	return head;
}

void push(int data,STU* head) //入队
{
	STU *p = head;
	STU *q = (STU *)malloc(sizeof(STU));
	memset(q, 0, sizeof(STU));
	if (p->next == NULL)
	{
		p->next = q;
		q->data = data;
		q->next = NULL;
	}
	else
	{
		while (p->next != NULL)
		{
			p = p->next;
		}
		p->next = q;
		q->data = data;
		q->next = NULL;
	}
}

int front(STU *head) // 输出头节点之后的第一个节点的数据
{
	int data = 0;
	STU *p = head->next;
	data = p->data;
	return data;
}
void pop(STU *head) // 删除头节点的第一个节点
{
	if (head->next == NULL)
	{
		return;
	}
	STU *p = head->next;
	head->next = p->next;
	free(p);
	p = NULL;
}

int size(STU *head)	// 查看链表
{
	STU *p = head->next;
	if (p == NULL)
	{
		return 0;
	}
	int i = 0;
	while (p != NULL)
	{
		i++;
		p = p->next;
	}
	return i;
}
int isempty(STU *head) // 查看链表是否为空
{
	STU *p = head->next;
	if (p == NULL)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
